<script>
    function enviar(){
        document.getElementById('controle_envio').value = '1';
        $('#PerfilAcessoIndexForm').submit();
    }
    
</script>

<?php
    // Controle de Seguranca
    $desabilitado_edit = $seguranca->verificar($controlador,'edit',$security);
    // ----------------------
?>

<div class="titulos">Perfil de Acesso</div>
<div class="perfilAcessos form">
    <?php echo $this->Form->create('PerfilAcesso'); ?>
        <input type="hidden" id="controle_envio" name="data[Controle][envio]" value="0" />
        <table id="tabela_mvc">
            <input type="hidden" id="PerfilAcessoId" value="<?php echo $this->data['Usuario']['id']; ?>" name="data[Usuario][id]"/>
            <tr>
                <th>Selecione o Usuário: </th>
                <td>
                    <select name="data[Usuario][id]" onchange="form.submit();">
                        <option value="0">Selecione o Usuário</option>
                        <?php foreach($usuarios as $item): ?>
                            <option <?php if ($this->data['Usuario']['id'] == $item['Usuario']['id']) echo 'selected'; ?> value="<?php echo $item['Usuario']['id'] ?>"><?php echo $item['Usuario']['nome']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            <?php if (isset($lista_menu)) { ?>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <th>Perfil de Acesso:</th>
                <td>
                    <table class="interno">
                        <tr>
                            <th><?php __('Descrição'); ?></th>
                            <th><?php __('Menu'); ?></th>
                            <th><?php __('Visualizar'); ?></th>
                            <th><?php __('Inserir'); ?></th>
                            <th><?php __('Alterar'); ?></th>
                            <th><?php __('Excluir'); ?></th>
                        </tr>
                        <?php $i = 0; foreach ($lista_menu as $menu): ?>
                            <tr>
                                <input type="hidden" value="<?php echo $menu['Menu']['id']; ?>" name="data[PerfilAcesso][<?php echo $i; ?>][menu_id]" />
                                <td><a href="#" rel="htmltooltip" class="link_tooltip"><?php echo $menu['Menu']['menu']; ?></a><div class="htmltooltip"><?php echo $menu['Menu']['descricao']; ?></div></td>
                                <th><input type="checkbox" name="data[PerfilAcesso][<?php echo $i; ?>][menu]" value="1" <?php echo isset($menu['PerfilAcesso']['0']['menu'])?$menu['PerfilAcesso']['0']['menu']==1?'checked':'':''; ?> /></th>
                                <th><?php if ($menu['Menu']['visualizar']){ ?><input type="checkbox" name="data[PerfilAcesso][<?php echo $i; ?>][visualizar]" value="1" <?php echo isset($menu['PerfilAcesso']['0']['visualizar'])?$menu['PerfilAcesso']['0']['visualizar']==1?'checked':'':''; ?> /><?php } else echo '&nbsp;'; ?></th>
                                <th><?php if ($menu['Menu']['inserir']){ ?><input type="checkbox" name="data[PerfilAcesso][<?php echo $i; ?>][inserir]" value="1" <?php echo isset($menu['PerfilAcesso']['0']['inserir'])?$menu['PerfilAcesso']['0']['inserir']==1?'checked':'':''; ?> /><?php } else echo '&nbsp;'; ?></th>
                                <th><?php if ($menu['Menu']['alterar']){ ?><input type="checkbox" name="data[PerfilAcesso][<?php echo $i; ?>][alterar]" value="1" <?php echo isset($menu['PerfilAcesso']['0']['alterar'])?$menu['PerfilAcesso']['0']['alterar']==1?'checked':'':''; ?> /><?php } else echo '&nbsp;'; ?></th>
                                <th><?php if ($menu['Menu']['excluir']){ ?><input type="checkbox" name="data[PerfilAcesso][<?php echo $i; ?>][excluir]" value="1" <?php echo isset($menu['PerfilAcesso']['0']['excluir'])?$menu['PerfilAcesso']['0']['excluir']==1?'checked':'':''; ?> /><?php } else echo '&nbsp;'; ?></th>
                            </tr>
                        <?php $i++; endforeach; ?>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="nobg">
                    <input type="button" value="Salvar" <?php echo $desabilitado_edit; ?> class="botao" onclick="enviar();" />
                </td>
            </tr>
            <?php } ?>
        </table>
    
    </div>